<?php
GLOBAL $AppUI, $projects, $company_id;
$perms =& $AppUI->acl();
$df = $AppUI->getPref('SHDATEFORMAT');
?>

<table id="idProjectList" width="100%" border="0" cellpadding="3" cellspacing="0" class="list">
<tr class="clickable">
    <th nowrap="nowrap" id="project_color_identifier" onclick="setMode(this)">
    	<?=$AppUI->_('Color')?>
    </th>
	<th nowrap="nowrap" id="project_name" onclick="setMode(this)">
		<?=$AppUI->_('Project Name')?>
	</th>
	<th nowrap="nowrap" id="company_name" onclick="setMode(this)">
		<?=$AppUI->_('Company')?>
	</th>
	<th nowrap="nowrap" id="user_username" onclick="setMode(this)">
		<?=$AppUI->_('Owner')?>
	</th>
	<th nowrap="nowrap" id="total_tasks" onclick="setMode(this)">
		<?=$AppUI->_('Tasks')?>
	</th>
	<th nowrap="nowrap" id="project_end_date" onclick="setMode(this)">
		<?=$AppUI->_('Finished')?>
	</th>
</tr>

<?php
$none = true;
$np = 1;
foreach ($projects as $row) {
	if (! $perms->checkModuleItem('projects', 'view', $row['project_id']))
		continue;

	if ($row['project_status'] == P_ARCHIVED) {
		$none = false;
		$end_date = intval( @$row["project_actual_end_date"] ) ? new CDate( $row["project_actual_end_date"] ) : null;

		$s = '<tr class="'.($np % 2 == 1 ? 'first' : 'second').'">'; $np++;
		$s .= '<td width="65" align="center" style="border: outset #eeeeee 2px;background-color:#'
			. $row["project_color_identifier"] . '">';
		$s .= '<font color="' . bestColor( $row["project_color_identifier"] ) . '">'
			. sprintf( "%.1f%%", $row["project_percent_complete"] )
			. '</font>';
		$s .= '</td>';

		$s .= '<td class="clickable" width="100%" onclick="viewProject('.$row["project_id"].')">';
		$s .= htmlspecialchars( $row["project_name"], ENT_QUOTES );
		$s .= '</td>';

		if ($perms->checkModuleItem('companies', 'access', $row['project_company'])) {
			$s .= '<td class="clickable" width="30%" onclick="Company('.$row["project_company"].').show()" title="' . htmlspecialchars( $row["company_description"], ENT_QUOTES ) . '">';
			$s .= htmlspecialchars( $row["company_name"], ENT_QUOTES ) . '</td>';
		} else {
			$s .= '<td>'.htmlspecialchars( $row["company_name"], ENT_QUOTES ).'</td>';
		}

		$s .= '<td nowrap="nowrap">' . htmlspecialchars( $row["user_username"], ENT_QUOTES ) . '</td>';
		$s .= '<td align="center" nowrap="nowrap">';
		$s .= $row["total_tasks"];
		$s .= '</td>';
		$s .= '<td align="right" nowrap="nowrap">';
		$s .= ($end_date ? $end_date->format( $df ) : '-');
		$s .= '</td>';
		$s .= '</tr>';
		echo $s;
	}
}
if ($none) {
	echo '<tr><td colspan="6">' . $AppUI->_( 'No projects available' ) . '</td></tr>';
}
?>
</table>
<script>
Table("idProjectList").setNormalHover(1);
</script>
